package com.yunchao.feature.lock.presentation.screen

import android.os.Bundle
import android.view.View
import by.kirich1409.viewbindingdelegate.viewBinding
import com.yunchao.feature.base.presentation.activity.BaseFragment
import com.yunchao.feature.base.presentation.ext.setDebouncedClickListener
import com.yunchao.feature.lock.R
import com.yunchao.feature.lock.databinding.FragmentLockCleanBinding
import com.yunchao.feature.lock.domain.model.LockInfoModel

internal class LockCleanFragment : LockFragment(R.layout.fragment_lock_clean) {

    private val binding: FragmentLockCleanBinding by viewBinding<FragmentLockCleanBinding>()

    override fun initView(view: View, savedInstanceState: Bundle?) {
        binding.cleanButton.setDebouncedClickListener {
            lockEPCInfo?.apply {
                viewModel.cleanLock(this)
            }
        }
    }

    override fun handlePageIdle() {
        binding.apply {
            lockNumber.text =
                getString(com.yunchao.feature.base.R.string.锁号)
            lockEpcContent.text =
                getString(com.yunchao.feature.base.R.string.EPC)
            lockClearLogTotal.text =
                getString(com.yunchao.feature.base.R.string.日志总数)
            logisticsLogTotal.text =
                getString(com.yunchao.feature.base.R.string.物流日志总数)
        }
    }

    override fun handlePageSuccess(lockInfoModel: LockInfoModel) {
        super.handlePageSuccess(lockInfoModel)
        binding.apply {
            lockNumber.text =
                getString(com.yunchao.feature.base.R.string.锁号STR, lockInfoModel.lockEPCInfo.id)
            lockEpcContent.text =
                getString(com.yunchao.feature.base.R.string.EPCSTR, lockInfoModel.lockEPCInfo.epc)
            lockClearLogTotal.text =
                getString(com.yunchao.feature.base.R.string.日志总数STR2, lockInfoModel.lockLogCount)
            logisticsLogTotal.text =
                getString(
                    com.yunchao.feature.base.R.string.物流日志总数STR2,
                    lockInfoModel.lockLogisticsCount
                )
        }
    }

    override fun onceScanLock() {
        viewModel.inventoryOnceAndLogCount()
    }
}